package com.chengn.queue.synchronous;

import com.chengn.factory.MyThreadFactory;

import java.util.concurrent.*;

public class SynchronousQueueMain {
    public static void main(String[] args) throws InterruptedException {


        ThreadPoolExecutor executor = new ThreadPoolExecutor(1,
                1,
                1,
                TimeUnit.SECONDS,
                new SynchronousQueue<>(),
                new MyThreadFactory());

        for (int i = 0; i < 5; ++i) {
            int finalI = i;
            executor.execute(() -> {
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (Exception ex) {
                    // TODO
                }
                System.out.println(finalI);
            });

            // TimeUnit.SECONDS.sleep(2);
        }
    }
}
